package edu.rutgers.crawler;

import java.util.ArrayList;

import org.htmlparser.NodeFilter;
import org.htmlparser.Parser;
import org.htmlparser.filters.NodeClassFilter;
import org.htmlparser.tags.LinkTag;
import org.htmlparser.util.NodeList;
import org.htmlparser.util.ParserException;
import org.htmlparser.util.SimpleNodeIterator;

/**
 * Finds link on the page.
 * 
 * @author dashali
 * 
 */
public class LinkFinder {
	public static ArrayList<String> find(Parser parser) {
		ArrayList<String> result = new ArrayList<String>();
		NodeFilter filter = new NodeClassFilter(LinkTag.class);
		NodeList list = new NodeList();
		try {
			list = parser.extractAllNodesThatMatch(filter);
		} catch (ParserException e) {
			e.printStackTrace();
		}
		SimpleNodeIterator sni = list.elements();
		while (sni.hasMoreNodes()) {
			LinkTag node = (LinkTag) sni.nextNode();
			result.add(node.getLink());
		}
		return result;

	}
}
